#include <stdlib.h>
#include <stdio.h>

#include "synqrone.h"

int main(int argc, char **argv) {
    if(argc<2) exit(1);

    sSynq *real=NULL, *simu=NULL;   // the real tree will contain the real state of the file system; the simu tree will be displayed and modified by the virtual actions until you apply them to the file system
    sAL *actions=NULL;

    // create the status tree
    real=synq_get_status(&argv[1], argc-1);    // give the extra arguments (must be the folders)
    if(!real) {
        printf("can't create synq\n");
        exit(1);
    }

    printf("real tree :\n");
    ST_print_debug(real->tree, argc-1);   // print the status data verbosely

    simu=synq_dup(real);
    printf("simu tree (copy of the real one) :\n");
    ST_print_debug(simu->tree, argc-1);   // print the status data verbosely

// <-- test file path
    {
        printf("file path test :\n");
        sST *tmp=FP_to_ST(simu->tree, "ludo6433/hoo");
        if(tmp) printf("\"%s\"@\"%s\"\n", tmp->name, ST_to_FP_s(tmp));
        else printf("fail\n");
    }
// -->

    // add some actions
    AL_append(&actions, AT_NOP);
    AL_append(&actions, AT_SYNC, "ludo6433/lulu_d/lulu_f", 1);

    printf("actions :\n");
    AL_print_debug(actions);

    printf("executing these actions on the simu tree...");
    if(AL_run(actions, simu, 1 /* simulate */))
        printf("fail\n");
    else
        printf("ok\n");
    synq_update_status(simu);

    printf("simu tree (after actions execution) :\n");
    ST_print_debug(simu->tree, argc-1);   // print the status data verbosely

    AL_free(actions);
    synq_free(real);
    synq_free(simu);

    malloc_stats();

    return 0;
}

